<?php

namespace app\admin\controller;


class Comment extends Base
{

    // 评论列表
    public function commentlist()
    {
        $comment_list = model('Comment')
            ->with('article,member')
            ->order('create_time', 'desc')
            ->paginate(10);
        $this->assign('commentList', $comment_list);
        return view();
    }


    // 删除评论
    public function commentdel()
    {
        $comment_info = model('Comment')
            ->with('article')
            ->find(input('post.id'));
        if (!$comment_info){
            abort('404','该评论不存在');
        }
        $result = $comment_info->delete();
        if ($result){
            $comment_info['article']->setDec('comment_num');
            $this->success('评论删除成功', 'admin/comment/commentlist');
        }else{
            $this->error('评论删除失败');
        }
    }
}
